<template>
    <div class="demo">
      <h2>学生姓名:{{ name }}</h2>
      <h2>学生年龄:{{ age }}</h2>
      <button @click="showMsg">点我展示年龄</button>
    </div>
  </template>
  
  <script>
  export default {
      name:'Student',
      data () {
          return {
              name:'张三',
              age:19
          }
      },
      methods:{
          showMsg(){
              alert("年龄为"+this.age)
          }
      },
      mounted(){
        this.$bus.$on('sendname',(data)=>{
            console.log("传来的名字为",data);
        })
      }
  }
  </script>
  
  <style>
      .demo{
          background-color: blanchedalmond;
      }
  </style>